﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoCadConvert
{
    public class Utility
    {
        public static double Cross(Point A, Point B, Point C)
        {
            return (B.X - A.X) * (C.Y - A.Y) - (C.X - A.X) * (B.Y - A.Y);
        }
        /* 判断线段AB与线段CD是否相交而且端点不相交，相交返回true */
        public static bool Intersect(Point A, Point B, Point C, Point D)
        {
            if (Math.Min(A.X, B.X) <= Math.Max(C.X, D.X) &&
                Math.Min(C.X, D.X) <= Math.Max(A.X, B.X) &&
                Math.Min(A.Y, B.Y) <= Math.Max(C.Y, D.Y) &&
                Math.Min(C.Y, D.Y) <= Math.Max(A.Y, B.Y) &&
                Cross(A, B, C) * Cross(A, B, D) < 0 &&//小于0表示在两侧，而不是同侧  
                Cross(C, D, A) * Cross(C, D, B) < 0)
                return true;
            else
                return false;
        }
        public static bool Intersect(Line l1,Line l2)
        {
            return Intersect(l1.V0, l1.V1, l2.V0, l2.V1);
        }
    }
}
